import { listPlugins } from "@/lib/api/buildInController";
import type { PluginInfo } from "@/lib/api/types";
import { Table, type TableProps } from "antd";
import { useEffect, useState } from "react";

const columns: TableProps<PluginInfo>['columns'] = [
  {
    title: "插件名称",
    dataIndex: "Name",
    key: "Name",
  },
  {
    title: "插件路径",
    dataIndex: "Path",
    key: "Path",
  },
  {
    title: "错误信息",
    dataIndex: "Err",
    key: "Err",
    render: (text: string) => {
      return <div>{text}</div>
    }
  },
]

export default function PluginPage() {
  const [pluginInfo, setPluginInfo] = useState([] as PluginInfo[])

  useEffect(() => {
    listPlugins({}).then(res => {
      setPluginInfo(res.plugins)
    }).catch(err => {
      console.log(err)
    })
  }, [])

  return <div>
    <Table<PluginInfo>
      columns={columns}
      dataSource={pluginInfo}
      rowKey="Name"
      pagination={false}
      size="small"
      locale={{ emptyText: "插件为空" }}
    />
  </div>
}
